#!/bin/sh
#

PATH_pwd=$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
source ${PATH_pwd}/../path.sh


##############################################################################
# 编译工具链
export MY_TOOL_CHAIN=
export MY_HOST=


##############################################################################
if [ -n "$1" ]; then 
    MY_TOOL_CHAIN=$1 
fi

if [ -n "$1" ]; then 
    MY_HOST=$2 
fi

echo "Param 1=$1, MY_TOOL_CHAIN=${MY_TOOL_CHAIN}"
echo "Param 2=$2, MY_HOST=${MY_HOST}"

##############################################################################
# 源码等路径

PATH_tmp=${PATH_pwd}/tmp
PATH_file=${PATH_pwd}/zeromq-4.3.4.tar.gz
PATH_src=${PATH_pwd}/tmp/zeromq-4.3.4

PATH_install=${MY_PATH_PREFIX}

##############################################################################
# 函数定义

PARAM_config="CC=${MY_TOOL_CHAIN}gcc CXX=${MY_TOOL_CHAIN}g++ --host=${MY_HOST}"
PARAM_config=${PARAM_config}" --enable-static=yes --enable-shared=no"
PARAM_config=${PARAM_config}" --without-docs --without-documentation"
PARAM_config=${PARAM_config}" --prefix=${PATH_install}"

function mk_preopen(){
    mkdir -p ${PATH_tmp}
    tar -xzf ${PATH_file} -C ${PATH_tmp};
}

function mk_configure(){
    echo "PATH_src=${PATH_src}"
    echo "PARAM_config=${PARAM_config}"

    cd ${PATH_src}
    ./configure ${PARAM_config}
}


function mk_all(){
    cd ${PATH_src}
    make -j8
}

function mk_install(){
    cd ${PATH_src}
    make install
}

function mk_clean(){
    rm -rf ${PATH_tmp}
}

##############################################################################
# 

mk_preopen
mk_configure
mk_all
mk_install
